<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>自动升级系统</title>
<link rel="shortcut icon" href="/public/Hplus/img/logo2.png">
<link href="/public/codemirror/theme/monokai.css" rel="stylesheet">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/layui/css/layui.css" rel="stylesheet">
<link href="/public/Hplus/css/style.css" rel="stylesheet">
<link href="/public/codemirror/lib/codemirror.css" rel="stylesheet">
<link href="/public/codemirror/addon/display/fullscreen.css" rel="stylesheet">
<!-- 配置页面 -->
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    	<div class="ibox float-e-margins">
	   		<div class="ibox-title" >
                <ol class="breadcrumb">
				  <li><a href="#">首页</a></li>
				  <li><a href="#">项目</a></li>
				  <li><a href="@{list.PackageListAction.query()}">ggservice</a></li>
				  <li class="active">配置</li>
				</ol>
            </div>
    		<div class="ibox-content">
    			<div class="row row-lg">
    				<div class="col-sm-12">
    				  <!-- Nav tabs -->
					  <ul class="nav nav-tabs" role="tablist">
					    <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">shell脚本</a></li>
					    <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
					    <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
					    <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
					  </ul>
					
					  <!-- Tab panes -->
					  <div class="tab-content">
					    <div role="tabpanel" class="tab-pane active" id="home">
					    <form class="form-horizontal" action="@{config.ConfigAction.saveCodeShell()}" id="codeForm">
					    	<input type="hidden" name="condition.projectName" id="project_name" value="${result?.project_name}" />
							<textarea id="code" name="condition.codeShell" style="width: 1000px;">${result?.command}</textarea>
							<button type="button" class="btn btn-primary" id="codeShell">保存</button>
							<button type="button" class="btn btn-danger" id="codeCancel" onclick="window.location.href=document.referrer; return false">取消</button>
						</form>
						</div>
					    <div role="tabpanel" class="tab-pane" id="profile">...</div>
					    <div role="tabpanel" class="tab-pane" id="messages">...</div>
					    <div role="tabpanel" class="tab-pane" id="settings">...</div>
					  </div>
    				</div>
    			</div>
            	
    		</div>
    	</div>
    </div>

	<!-- 你的HTML代码 -->
	<script src="/public/javascripts/jquery-1.11.1.min.js"></script>
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script src="/public/layui/lay/dest/layui.all.js"></script>
	<!-- 引入CodeMirror核心文件 -->
	<script src="/public/codemirror/lib/codemirror.js"></script>
	<script src="/public/codemirror/mode/shell/shell.js"></script>
	<script src="/public/codemirror/addon/selection/active-line.js"></script>
	<script src="/public/codemirror/addon/edit/matchbrackets.js"></script>
	<script src="/public/codemirror/addon/display/fullscreen.js"></script>
	
	<script src="@{'/public/autodeploy/verify.js'}"></script>
	<script type="text/javascript">
		var editor = CodeMirror.fromTextArea(document.getElementById("code"),{
			theme: 'monokai', //使用monokai模板
			styleActiveLine: true, //当前行背景高亮
			lineNumbers: true, //显示行数
			indentUnit: 4, //缩进单位4
			matchBrackets: true, //括号匹配
			lineWrapping: true, //自动换行
		});
		editor.setOption("extraKeys", {
	        // Tab键换成4个空格
	        Tab: function(cm) {
	            var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
	            cm.replaceSelection(spaces);
	        },
	        // F11键切换全屏
	        "F11": function(cm) {
	            cm.setOption("fullScreen", !cm.getOption("fullScreen"));
	        },
	        // Esc键退出全屏
	        "Esc": function(cm) {
	            if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
	        }
	    });
		
		$("#codeShell").on('click', function(e){
			editor.save();
			
			var formData = new FormData(document.getElementById("codeForm"));
			   /* formData.append("condition.projectName", '${result?.project_name}'); */
			  
			   $.ajax({
			    	url:"@{config.ConfigAction.saveCodeShell()}",
			    	type:"POST",
			    	data:formData,
			    	processData: false,
			    	contentType: false,
			    	success:function(data){
			    		if(data){
			    			layer.alert("保存成功", function(index){
			    				window.location.href="/list/PackageListAction/query?condition.projectName=${result?.project_name}";
			    				layer.close(index);
			    			});
			    		}else{
			    			layer.alert("保存失败");
			    		}
			    	},
			    	error:function(xhr, status, error){
			    		layer.alert("网络错误");
			    	}
			  });
			
			/* $("#codeForm").submit(); */
		});
		
	</script>
</body>
</html>